package org.komarichin.jdo.persistence;

import org.komarichin.beans.IRole;

import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

/**
 * Created by IntelliJ IDEA.
 * User: Michael Komarichin
 * Date: 04.10.2009
 * Time: 10:29:03
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class Role implements IRole {

    private static final long serialVersionUID = 6933754461521051224L;
    @PrimaryKey
    @Persistent(valueStrategy = javax.jdo.annotations.IdGeneratorStrategy.IDENTITY)
    private Long id;
    @Persistent
    private String name;
    @Persistent
    private Long permission;

    public Role() {
    }

    public Role(Long id, String name, Long permission) {
        this.id = id;
        this.name = name;
        this.permission = permission;
    }

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void setName(String name) {
        this.name = name;
    }

    @Override
    public Long getPermission() {
        return permission;
    }

    @Override
    public void setPermission(Long permission) {
        this.permission = permission;
    }



    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder();
        sb.append("Role");
        sb.append("{id=").append(id);
        sb.append(", name='").append(name).append('\'');
        sb.append(", permission=").append(permission);
        sb.append('}');
        return sb.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Role)) return false;

        Role role = (Role) o;

        if (id != null ? !id.equals(role.id) : role.id != null) return false;
        if (!name.equals(role.name)) return false;
        if (!permission.equals(role.permission)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + name.hashCode();
        result = 31 * result + permission.hashCode();
        return result;
    }
}
